import { KeymapEventHandler, Scope, SuggestModal } from "obsidian";

export interface Chooser<T> {
    /**活动项索引 */
    selectedItem: number;
    suggestions: HTMLDivElement[];
    values: T[];

    setSelectedItem(index: number, evt: MouseEvent | KeyboardEvent): void;
    setSuggestions(suggestions: T[]): void;
    useSelectedItem(evt: KeyboardEvent): void;
}

export interface SharedScope extends Scope {

    /**注册的键盘事件 */
    keys: KeymapEventHandler[];

}

export class SharedSuggestModal<T> extends SuggestModal<T>{

    protected _getChooser(): Chooser<T> { return (this as any).chooser; }
    protected _getSharedScope(): SharedScope { return this.scope as SharedScope; }

    /**更新列表 */
    protected _updateSuggestions() { (this as any).updateSuggestions(); }

    getSuggestions(query: string): T[] | Promise<T[]> {
        throw new Error("Method not implemented.");
    }
    renderSuggestion(value: T, el: HTMLElement) {
        throw new Error("Method not implemented.");
    }
    onChooseSuggestion(item: T, evt: MouseEvent | KeyboardEvent) {
        throw new Error("Method not implemented.");
    }

}
